package com.dynabook.ems.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dynabook.ems.mapper.UsersMapper;
import com.dynabook.ems.model.entity.Users;
import com.dynabook.ems.model.vo.UserLoginVO;
import com.dynabook.ems.service.UsersService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* @author tester
* @description 针对表【users(User information)】的数据库操作Service实现
* @createDate 2025-06-16 17:53:13
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService{

    @Override
    public UserLoginVO getLoginUser(String cookie) {
        UserLoginVO users = this.baseMapper.getLoginUser(cookie);
        return users;
    }

    @Override
    public List<String> getSampleMail(int roleId) {
        return  this.baseMapper.getSampleMail(roleId);
    }

    @Override
    public UserLoginVO getLoginUserInfo(String userId) {
        return this.baseMapper.getLoginUserInfo(userId);
    }

    @Override
    public List<String> getSectionMails(String sectionId) {
        String sectionMails = this.baseMapper.getSectionMails(sectionId);
        if (sectionMails == null) {
            return new ArrayList<>();
        }
        List<String> list = JSONUtil.toList(sectionMails, String.class);
        return Optional.ofNullable(list).orElse(new ArrayList<>());
    }
}




